define(function(require, exports, module){
	require("resource/js/easyui/themes/icon.css");
	require("resource/js/easyui/easyloader.js");
	var AJAX = require("resource/js/component/ajax.js");
	var EUtil = require("resource/js/component/easyutil.js");
	var easycombobox = require("resource/js/component/easycombobox.js");



	using(["validatebox"],function(){
		$.extend($.fn.validatebox.defaults.rules, {
			lowerSegregationRules: {
				validator: function(value){
					return /^[0-9]+(\.[0-9]{0,2})?$/.test(value);
				},message: "只能为正整数,两位小数",
				validator: function(value){
					var middleSegregation = $("#middleSegregation").val();
					if(Number(value) <= Number(middleSegregation)){
						return true;
					}
				},message: "参数范围有误：a ≤ 离析度 ≤ b"
			},
			middleSegregationRules: {
				validator: function(value){
					return /^[0-9]+(\.[0-9]{0,2})?$/.test(value);
				},message: "只能为正整数,两位小数",
				validator: function(value){
					var lowerSegregation = $("#lowerSegregation").val();
					if(Number(value) >= Number(lowerSegregation)){
						return true;
					}
				},message: "参数范围有误：a ≤ 离析度 ≤ b"
			},
			highSegregationRules: {
				validator: function(value){
					return /^[0-9]+(\.[0-9]{0,2})?$/.test(value);
				},message: "只能为正整数,两位小数",
				validator: function(value){
					var lowerSegregation = $("#lowerSegregation").val();
					var middleSegregation = $("#middleSegregation").val();
					if(Number(lowerSegregation) <= Number(middleSegregation) && Number(middleSegregation) <= Number(value)){
						return true;
					}
				},message: "参数范围有误：a ≤ b ≤ 重度离析范围"
			}
		});
	});

	
	var initpage = function(){
		var sectionId = sessionStorage.getItem('sectionId');
		if(sectionId == null || sectionId == undefined){
			sectionId = 0;
		}
       //根据标段查询出对应的参数
		var data = getBySecationId(sectionId);
		if(data == null || data == undefined){//添加
			document.getElementById("save").style.display="";
		}else{//修改
			document.getElementById("save").style.display="none";
			document.getElementById("update").style.display="";
			//赋值
            $("#searchform").form('load',data);
		}

		//添加
		$('#saveClick').unbind('click').bind('click',function(){
			using("form",function(){
				if($("#searchform").form("validate")){
					var obj = $("#searchform").serializeJson();
					//处理标段Id
					obj.sectionId = sectionId;
					AJAX.init().sync().success(function(code,msg,data){
						if(code==0){
							$.messager.show({ title:"系统提示", msg:msg, timeout:2000, showType:'slide' });
							initpage();
						}
					}).post(BASEPATH + '/dcs/modify/saveDataModify.htm',obj);
				}
			});
		});
		//修改
		$('#updateClick').unbind('click').bind('click',function(){
			using("form",function(){
				if($("#searchform").form("validate")){
					var obj = $("#searchform").serializeJson();
					//处理标段Id
					obj.sectionId = sectionId;
					AJAX.init().success(function(code,msg,data){
						if(code==0){
							$.messager.show({ title:"系统提示", msg:msg, timeout:2000, showType:'slide' });
							initpage();
						}
					}).post(BASEPATH + '/dcs/modify/saveDataModify.htm',obj);

				}
			});
		});
	}


//根据标段id获取离析参数
	function getBySecationId(sectionId){
		var datas  = undefined;
		AJAX.init().sync().success(function(code,msg,data){
			//获取Data数据
			datas = data;
		}).error(function(code,msg,data){
			}).post(BASEPATH+'/dcs/modify/queryDataModifyBySectionId.htm?sectionId='+sectionId);
	    return datas;
	}

	module.exports = {
		trans:function(){
			using(["parser","dialog","datagrid","combobox" ],function(){
				initpage();
			});
		}
	}
});
